home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
dir.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-27
|
3KB
|
114 lines
#include <MacHeaders>
#define NULL 0L
static OSErr err;
static int gHaveAUX = FALSE;
/** PathNameFromDirID *********************************************************/
char *
PathNameFromDirID(DirID, vRefNum, s)
long DirID;
short vRefNum;
char *s;
{
CInfoPBRec block;
Str255 directoryName;
/* *s = 0; Don't want to null because file name is there */
block.dirInfo.ioNamePtr = directoryName;
block.dirInfo.ioDrParID = DirID;
do {
block.dirInfo.ioVRefNum = vRefNum;
block.dirInfo.ioFDirIndex = -1;
block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
if (err = PBGetCatInfo(&block,false))
{
SysBeep(1);
return;
}
if (gHaveAUX) {
if (directoryName[1] != '/')
/* If this isn't root (i.e. '/'), append a slash ('/') */
pStrcat(directoryName,"\p/");
} else
/* Append a Macintosh style colon (':') */
pStrcat(directoryName,"\p:");
pStrcat(directoryName,s);
pStrcpy(s,directoryName);
} while (block.dirInfo.ioDrDirID != fsRtDirID);
return(s);
}
/** PathNameFromWD ************************************************************/
char *
PathNameFromWD(vRefNum,s)
long vRefNum;
char *s;
{
WDPBRec myBlock;
/*
/* PBGetWDInfo has a bug under A/UX 1.1. If vRefNum is a real vRefNum
/* and not a wdRefNum, then it returns garbage. Since A/UX has only 1
/* volume (in the Macintosh sense) and only 1 root directory, this can
/* occur only when a file has been selected in the root directory (/).
/* So we look for this and hard code the DirID and vRefNum. */
if (gHaveAUX && (vRefNum == -1))
return(PathNameFromDirID(2,-1,s));
myBlock.ioNamePtr = NULL;
myBlock.ioVRefNum = vRefNum;
myBlock.ioWDIndex = 0;
myBlock.ioWDProcID = 0;
/* Change the Working Directory number in vRefnum into a real vRefnum */
/* and DirID. The real vRefnum is returned in ioVRefnum, and the real */
/* DirID is returned in ioWDDirID. */
if (err = PBGetWDInfo(&myBlock,false))
{
SysBeep(1); return;
}
return(PathNameFromDirID(myBlock.ioWDDirID,myBlock.ioWDVRefNum,s));
};
condensePathname(path)
char *path;
{
char str[256], *ptr, *ptr2;
extern int condensed;
if (!condensed) return;
ptoc(path);
for (ptr = path; *ptr && (*ptr != ':'); ptr++);
strncpy(str,path, (int)(ptr - path));
str[ptr - path] = 0;
for (ptr = path + strlen(path); (*ptr != ':') && (ptr > path); ptr--);
ptr2 = ptr--;
while ((*ptr != ':') && (ptr > path)) ptr--;
if (ptr < path)
{
strcpy(str,ptr2);
}
else
{
strcat(str,":...");
strcat(str,ptr);
}
strcpy(path,str);
ctop(path);
}